package designpattern;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DynamicProxy {
    public static void main(String[] args) {
        InvocationHandler invocationHandler = new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("before invoke()");
                method.invoke(proxy, args);
                System.out.println("after invoke()");
                return new Object();
            }
        };

        Test test = (Test) Proxy.newProxyInstance(Test.class.getClassLoader(), new Class<?>[]{Test.class}, invocationHandler);
        test.func1();
        test.func2();
    }
}

interface Test {
    public String func1();

    public String func2();
}

class Test0 implements Test {
    @Override
    public String func1() {
        return "22";
    }

    @Override
    public String func2() {
        return "33";
    }
}

